package com.hulang.sms.sending.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class DateUtil {


    /**
     * 获取今天是今年的第几周
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/5/28 11:45
     */
    public static String getWeekNumForToday(String today) {
        if (today.length() == 10) {
            today += " 00:00:30";
        }
        LocalDate localDate = LocalDate.parse(today, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        WeekFields weekFields = WeekFields.ISO;

        return "第" + localDate.get(weekFields.weekOfWeekBasedYear()) + "周";
    }

    /**
     * 获取距离当前时间【dayNum】天后的日期 dayNum = 1 表示取明天的日期
     * 传负数表示获取之前的日期
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/1/18 14:37
     */
    public static String getAfterDayDateYMDHMS(int dayNum) {
        LocalDateTime localDateTime = LocalDateTime.now();
        LocalDateTime localDateTimeAdd = localDateTime.plusDays(dayNum);
        return localDateTime2YMDHMS(localDateTimeAdd);
    }


    /**
     * Mon 转 周一
     * 以此类推
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/5/23 18:24
     */
    public static String englishWeekToChinese(String englishWeek) {
        switch (englishWeek) {
            case "Mon":
                return "周一";
            case "Tues":
                return "周二";
            case "Wed":
                return "周三";
            case "Thur":
                return "周四";
            case "Fri":
                return "周五";
            case "Sat":
                return "周六";
            case "Sun":
                return "周日";
        }
        return null;
    }

    /**
     * 日期转星期
     *
     * @param datetime
     * @return
     */
    public static String dateToWeek(String datetime) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        //String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        String[] weekDays = {"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"};
        Calendar cal = Calendar.getInstance(); // 获得一个日历
        Date datet = null;
        try {
            datet = f.parse(datetime);
            cal.setTime(datet);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
        if (w < 0)
            w = 0;
        return weekDays[w];
    }

    public static String dateToWeek_ZH(String datetime) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        String[] weekDays = {"日", "一", "二", "三", "四", "五", "六"};
        //String[] weekDays = {"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"};
        Calendar cal = Calendar.getInstance(); // 获得一个日历
        Date datet = null;
        try {
            datet = f.parse(datetime);
            cal.setTime(datet);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
        if (w < 0)
            w = 0;
        return weekDays[w];
    }

    /**
     * 获取某年某月有几天
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2018/12/12 17:42
     */
    public static int getDaysByYearAndMonth(int year, int month) {
        int days = 0;
        boolean isLeapYear = false;
        if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {//闰年
            isLeapYear = true;
        } else {//非闰年
            isLeapYear = false;
        }
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 2:
                if (isLeapYear) {
                    days = 29;
                } else {
                    days = 28;
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            default:
                System.out.println("error!!!");
                break;
        }
        return days;
    }


    /**
     * 获取一个月有几天
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2018/12/12 15:28
     */
    public static int getCurrentMonthLastDay() {
        Calendar a = Calendar.getInstance();
        a.set(Calendar.DATE, 1);//把日期设置为当月第一天
        a.roll(Calendar.DATE, -1);//日期回滚一天，也就是最后一天
        int maxDate = a.get(Calendar.DATE);
        return maxDate;
    }

    /**
     * yyyy-MM-dd
     *
     * @param date
     * @return yyyy-MM-dd
     */
    public static String dateToYMD(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    /**
     * 两个星期几之间隔了几天
     * firstWeekDay Sun
     * secondWeekDay Sun
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/4/15 15:10
     */
    public static int dayBtTwoWeekDay(String firstWeekDay, String secondWeekDay) {
        if ("Mon".equals(firstWeekDay)) {
            switch (secondWeekDay) {
                case "Mon":
                    return 1;
                case "Tues":
                    return 2;
                case "Wed":
                    return 3;
                case "Thur":
                    return 4;
                case "Fri":
                    return 5;
                case "Sat":
                    return 6;
                case "Sun":
                    return 7;
            }
        }

        if ("Tues".equals(firstWeekDay)) {
            switch (secondWeekDay) {
                case "Tues":
                    return 1;
                case "Wed":
                    return 2;
                case "Thur":
                    return 3;
                case "Fri":
                    return 4;
                case "Sat":
                    return 5;
                case "Sun":
                    return 6;
            }
        }
        if ("Wed".equals(firstWeekDay)) {
            switch (secondWeekDay) {
                case "Wed":
                    return 1;
                case "Thur":
                    return 2;
                case "Fri":
                    return 3;
                case "Sat":
                    return 4;
                case "Sun":
                    return 5;
            }
        }
        if ("Thur".equals(firstWeekDay)) {
            switch (secondWeekDay) {
                case "Thur":
                    return 1;
                case "Fri":
                    return 2;
                case "Sat":
                    return 3;
                case "Sun":
                    return 4;
            }
        }
        if ("Fri".equals(firstWeekDay)) {
            switch (secondWeekDay) {
                case "Fri":
                    return 1;
                case "Sat":
                    return 2;
                case "Sun":
                    return 3;
            }
        }
        if ("Sat".equals(firstWeekDay)) {
            switch (secondWeekDay) {
                case "Sat":
                    return 1;
                case "Sun":
                    return 2;
            }
        }
        if ("Sun".equals(firstWeekDay)) {
            switch (secondWeekDay) {
                case "Sun":
                    return 1;
            }
        }
        return 7;
    }

    /**
     * @param date
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String dateToYMDHMS(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    /**
     * @param date
     * @return
     */
    public static String dateToYMDhms(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
        return sdf.format(date);
    }

    /**
     * @param date
     * @return 精确到毫秒值 yyyyMMddHHmmssSSS
     */
    public static String date2YMDhms(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return sdf.format(date);
    }

    /**
     * @param date
     * @return 精确到秒值 yyyyMMddHHmmss
     */
    public static String date2YMDhms14(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        return sdf.format(date);
    }

    /**
     * 字符串形式日期转换成标准日期 String --> Date "yyyy-MM-dd"-->yyyy-MM-dd
     */
    public static Date YMDToDate(String date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return dateFormat.parse(date);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 字符串形式日期转换成标准日期 String --> Date "yyyy-MM-dd HH:mm:ss"-->yyyy-MM-dd HH:mm:ss
     */
    public static Date YMDHMSToDate(String date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return dateFormat.parse(date);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    public static String getTheYear() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Date date = new Date();
        String formatDate = sdf.format(date);
        return formatDate;
    }

    /**
     * 起始时间与结束时间间隔不能少于40分钟
     *
     * @param begTm
     * @param endTm
     * @return 开始+40分钟<结束返回true
     */
    public static boolean checkBw40MinBegTmAndEndTm(String begTm, String endTm) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date begTmParse = null;
        Date endTmParse = null;
        try {
            begTmParse = df.parse(begTm);
            endTmParse = df.parse(endTm);
            return endTmParse.getTime() - 40L * 60L * 1000L >= begTmParse.getTime() ? true : false;
        } catch (Exception exception) {
            return false;
        }

    }

    /**
     * 比较两个时间的大小
     *
     * @param begTm
     * @param endTm
     * @return 开始<结束返回true
                    */
    public static boolean checkBegTmAndEndTm(String begTm, String endTm) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date begTmParse = null;
        Date endTmParse = null;
        try {
            begTmParse = df.parse(begTm);
            endTmParse = df.parse(endTm);
            return begTmParse.getTime() <= endTmParse.getTime() ? true : false;
        } catch (Exception exception) {
            return false;
        }

    }

    /**
     * 计算两个日期之间的间隔天数（默认结束时间大于起始时间）
     *
     * @param begTm
     * @param endTm
     * @return
     */
    public static int checkDaysBegTmAndEndTm(String begTm, String endTm) {

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date begTmParse = null;
        Date endTmParse = null;
        try {
            begTmParse = df.parse(begTm);
            endTmParse = df.parse(endTm);
            long start = begTmParse.getTime();
            long end = endTmParse.getTime();

            int days = (int) ((end - start) / 1000L / 60L / 60L / 24L);
            return days;
        } catch (Exception exception) {
            return 0;
        }

    }

    /**
     * @param str     需要校验的时间字符串 2018-09-10 或者2018-09-10 12:23:38
     * @param pattern 时间的格式 yyyy-MM-dd 或者yyyy-MM-dd HH:mm:ss(24小时制)
     * @return
     */
    public static boolean isValidDate(String str, String pattern) {
        boolean convertSuccess = true;
        // 指定日期格式为四位年/两位月份/两位日期，注意yyyy/MM/dd区分大小写；
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            // 设置lenient为false.
            // 否则SimpleDateFormat会比较宽松地验证日期，比如2007/02/29会被接受，并转换成2007/03/01
            format.setLenient(false);
            format.parse(str);
        } catch (ParseException e) {
            // e.printStackTrace();
            // 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
            convertSuccess = false;
        }
        return convertSuccess;
    }

    /**
     * 获取当前时间一周后的时间
     *
     * @param date
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String getAfterWeekDateYMDHMS(Date date) {

        return dateToYMDHMS(new Date(date.getTime() + 7L * 24L * 3600L * 1000L));
    }

    /**
     * 返回当天零时零分零秒的时间
     *
     * @param date
     * @return yyyy-MM-dd 00:00:00
     */
    public static String getBeforOneDateYMDHMS(Date date) {
        String dateToYMD = dateToYMD(date);
        return dateToYMD + " 00:00:00";
    }

    /**
     * 当前时间与begTm的前十分钟的大小
     *
     * @param toDate
     * @param begTm
     * @return 当前时间与begTm的前十分钟的大小
     */
    public static long checkDaysBeforeTenMinuteCurrTmAndBegTm(String toDate, String begTm) {
        Date toDay = YMDHMSToDate(toDate);
        Date begTmDate = YMDHMSToDate(begTm);

        return toDay.getTime() - (begTmDate.getTime() + 10 * 60 * 1000);
    }



    /**
     * 判断两个日期是不是同一天
     *
     * @param time1 yyyy-MM-dd HH:mm:ss
     * @param time1 yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static boolean isSameDay(String time1, String time2) {
        String time1Ymd = time1.split(" ")[0];
        String time2Ymd = time2.split(" ")[0];

        return time1Ymd.equals(time2Ymd);
    }

    /**
     * 返回当天下班的时间
     * yyyy-mm-dd MM:HH:ss 默认返回当天的21:59:59
     * 做不完可以加班嘛  哈哈
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2018/10/28 15:04
     */
    public static String getTimeToEndWorkOfToday() {
        String ymd = DateUtil.dateToYMD(new Date());
        return ymd + " 21:59:59";
    }

    /**
     * 根据当前时间获取昨天的日期
     *
     * @param date
     * @param i
     * @return
     */
    public static String getTimeToYesterday(Date date, int i) {
        long currentTime = date.getTime();
        //再获取几天后的下班时间
        currentTime -= ((long) i) * 24L * 3600L * 1000L;
        Date dates = new Date(currentTime);
        return DateUtil.dateToYMD(dates);
    }

    /**
     * localDateTime2YMDHMS
     * 返回的格式为 yyyy-MM-dd HH:mm:ss
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/1/7 12:04
     */
    public static String localDateTime2YMDHMS(LocalDateTime localDateTime) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return df.format(localDateTime);
    }

    /**
     * 获取几天之后的下班时间
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2018/10/28 15:51
     * <p>
     * yyyy-mm-dd MM:HH:ss
     */
    public static String getTimeToEndWorkOfSomeDayAfter(int dayNum) {
        LocalDateTime localDateTime = LocalDateTime.now();
        LocalDateTime localDateTimeAdd = localDateTime.plusDays(dayNum);
        return localDateTime2YMDHMS(localDateTimeAdd);
    }

    /**
     * 根据当前时间获取几天后的时间
     *
     * @param date
     * @param i
     * @return
     */
    public static String getTimeToSomeDayAfter(Date date, int i) {
        String timeToToday = DateUtil.dateToYMD(date) + " 21:59:59";
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date currDay = dateFormat.parse(timeToToday);
            long currentTm = currDay.getTime();

            //再获取几天后的下班时间
            currentTm += ((long) i) * 24L * 3600L * 1000L;
            Date dates = new Date(currentTm);
            //转换一下格式返回
            return DateUtil.dateToYMDHMS(dates);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 根据当前时间获取上周日期区间
     *
     * @param date
     * @return
     */
    public static String getTimeToLastWeek(Date date) {
        Calendar calendarSt = Calendar.getInstance();
        Calendar calendarEt = Calendar.getInstance();
        calendarSt.setTime(date);
        calendarEt.setTime(date);
        int dayOfWeek = calendarSt.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayOfWeek <= 0) {
            dayOfWeek = 7;
        }
        int offsetSt = 1 - dayOfWeek;
        int offsetEt = 7 - dayOfWeek;
        calendarSt.add(Calendar.DATE, offsetSt - 7);
        calendarEt.add(Calendar.DATE, offsetEt - 7);
        String startTm = DateUtil.dateToYMD(calendarSt.getTime());
        String endTm = DateUtil.dateToYMD(calendarEt.getTime());
        return startTm + "," + endTm;
    }

    /**
     * 根据当前时间获取本周日期区间
     *
     * @param date
     * @return
     */
    public static String getTimeToTheWeek(Date date) {
        Calendar calendarSt = Calendar.getInstance();
        Calendar calendarEt = Calendar.getInstance();
        calendarSt.setTime(date);
        calendarEt.setTime(date);
        int dayOfWeek = calendarSt.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayOfWeek <= 0) {
            dayOfWeek = 7;
        }
        int offsetSt = 1 - dayOfWeek;
        int offsetEt = 7 - dayOfWeek;
        calendarSt.add(Calendar.DATE, offsetSt);
        calendarEt.add(Calendar.DATE, offsetEt);
        String startTm = DateUtil.dateToYMD(calendarSt.getTime());
        String endTm = DateUtil.dateToYMD(calendarEt.getTime());
        return startTm + "," + endTm;
    }

    /**
     * 根据当前时间获取本月日期区间
     *
     * @param date
     * @return
     */
    public static String getTimeToTheMonth(Date date) {
        Calendar calendarSt = Calendar.getInstance();
        calendarSt.setTime(date);
        //  calendarSt.add(Calendar.MONTH, -1);
        calendarSt.set(Calendar.DAY_OF_MONTH, 1);
        String startTm = DateUtil.dateToYMD(calendarSt.getTime());
        Calendar calendarEt = Calendar.getInstance();
        calendarEt.setTime(date);
        //  calendarEt.add(Calendar.MONTH, -1);
        calendarEt.set(Calendar.DAY_OF_MONTH, calendarEt.getActualMaximum(Calendar.DAY_OF_MONTH));
        String endTm = DateUtil.dateToYMD(calendarEt.getTime());

        return startTm + "," + endTm;
    }

    /**
     * 根据当前时间获取上月日期区间
     *
     * @param date
     * @return
     */
    public static String getTimeToLastMonth(Date date) {
        Calendar calendarSt = Calendar.getInstance();
        calendarSt.setTime(date);
        calendarSt.add(Calendar.MONTH, -1);
        calendarSt.set(Calendar.DAY_OF_MONTH, 1);
        String startTm = DateUtil.dateToYMD(calendarSt.getTime());
        Calendar calendarEt = Calendar.getInstance();
        calendarEt.setTime(date);
        calendarEt.add(Calendar.MONTH, -1);
        calendarEt.set(Calendar.DAY_OF_MONTH, calendarEt.getActualMaximum(Calendar.DAY_OF_MONTH));
        String endTm = DateUtil.dateToYMD(calendarEt.getTime());
        return startTm + "," + endTm;
    }

    /**
     * 根据当前时间获取上月最后一天
     *
     * @return
     */
    public static String getLastMonthFinalDay(Date date) {
        Calendar calendarEt = Calendar.getInstance();
        calendarEt.setTime(date);
        calendarEt.add(Calendar.MONTH, -1);
        calendarEt.set(Calendar.DAY_OF_MONTH, calendarEt.getActualMaximum(Calendar.DAY_OF_MONTH));
        String endTm = DateUtil.dateToYMD(calendarEt.getTime());
        return endTm;
    }

    /**
     * 今夕是何月
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2018/12/12 16:20
     */
    public static int getCurrentMonth() {

        //yyyy-mm-dd
        String s = dateToYMD(new Date());
        String month = s.substring(5, 7);
        return Integer.parseInt(month);
    }

    /**
     * 获取两个时间的时间差（小时）
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/1/7 13:48
     */
    public static int getHourFromTwoTime(String begTm, String endTm) {
        LocalDateTime start = localDateTimeParse(begTm, "yyyy-MM-dd HH:mm:ss");
        LocalDateTime end = localDateTimeParse(endTm, "yyyy-MM-dd HH:mm:ss");
        Duration between = Duration.between(start, end);
        int betweenDays = (int) between.toHours();
        return Math.abs(betweenDays);
    }

    /**
     * 获取指定时间之后的时间，之前用负数
     *
     * @param appointedTm
     * @param minute
     * @return
     */
    public static String getAppointedTmAfterTmByHour(String appointedTm, int minute) {
        LocalDateTime start = localDateTimeParse(appointedTm, "yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = start.plusMinutes(minute);
        return localDateTime2YMDHMS(localDateTime);
    }

    /**
     * 获取两个时间的时间差（分钟）
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/1/7 13:48
     */
    public static int getMinuteFromTwoTime(String begTm, String endTm) {
        LocalDateTime start = localDateTimeParse(begTm, "yyyy-MM-dd HH:mm:ss");
        LocalDateTime end = localDateTimeParse(endTm, "yyyy-MM-dd HH:mm:ss");
        Duration between = Duration.between(start, end);
        int betweenMinutes = (int) between.toMinutes();
        return Math.abs(betweenMinutes);
    }

    /**
     * 获取两个时间的时间差（秒）
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/1/7 13:48
     */
    public static int getSecondFromTwoTime(String begTm, String endTm) {
        LocalDateTime start = localDateTimeParse(begTm, "yyyy-MM-dd HH:mm:ss");
        LocalDateTime end = localDateTimeParse(endTm, "yyyy-MM-dd HH:mm:ss");
        Duration between = Duration.between(start, end);
        int betweenSeconds = ((int) between.toMillis()) / 1000;
        return Math.abs(betweenSeconds);
    }

    /**
     * 字符串转LocalDateTime
     * 比如yyyy-mm-dd HH:mm:ss 转LocalDateTime
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/1/7 10:55
     */
    public static LocalDateTime localDateTimeParse(String time, String pattern) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern(pattern);
        return LocalDateTime.parse(time, df);
    }

    /**
     * 获取一个月的第一天
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/5/17 10:34
     */
    public static String getFirstDayOfMonth() {
        LocalDate today = LocalDate.now();
        LocalDate firstday = LocalDate.of(today.getYear(), today.getMonth(), 1);
        LocalDateTime firstDayTime = localDateToLocalDateTime(firstday);
        return localDateTime2YMDHMS(firstDayTime);
    }

    /**
     * 获取某天的下个月的当天 2019-10-10 --> 2019-11-10
     *
     * @param someDay
     * @return
     */
    public static String getNextMonthSomeDay(String someDay) {
        if (someDay.length() == 10) {
            someDay = someDay + " 00:00:00";
        }
        LocalDateTime localDateTimeParse = localDateTimeParse(someDay, "yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = localDateTimeParse.plusMonths(1);
        return localDateTime2YMDHMS(localDateTime);
    }

    /**
     * LocalDate To LocalDateTime
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/5/17 14:13
     */
    public static LocalDateTime localDateToLocalDateTime(LocalDate localDate) {

        ZoneId zone = ZoneId.systemDefault();
        Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
        Date date = Date.from(instant);

        instant = date.toInstant();
        zone = ZoneId.systemDefault();
        return LocalDateTime.ofInstant(instant, zone);
    }

    /**
     * 获取一个月的最后一天
     *
     * @return
     * @throws
     * @author 胡浪
     * @date 2019/5/17 10:35
     */
    public static String getLastDayOfMonth() {
        LocalDate today = LocalDate.now();
        LocalDate lastDay = today.with(TemporalAdjusters.lastDayOfMonth());
        LocalDateTime lastDayTime = localDateToLocalDateTime(lastDay);
        return localDateTime2YMDHMS(lastDayTime);
    }


    public static String getTimeNow() {
        LocalTime time = LocalTime.now();
        String timeStr = time.toString();
        return timeStr.substring(0, 5);
    }

    public static boolean isMorning() {
        String timeNow = getTimeNow();
        int r = timeNow.compareTo("09:30");
        if (r <= 0) {
            return true;
        }
        return false;
    }


    public static boolean isNoon() {
        String timeNow = getTimeNow();
        int r = timeNow.compareTo("09:30");
        int i = timeNow.compareTo("12:00");
        if (r > 0 && i < 0) {
            return true;
        }
        return false;
    }

    public static boolean isAfterNoon() {
        String timeNow = getTimeNow();
        int r = timeNow.compareTo("12:00");
        int i = timeNow.compareTo("18:30");
        if (r > 0 && i < 0) {
            return true;
        }
        return false;
    }

    public static boolean isNigth() {
        String timeNow = getTimeNow();
        int r = timeNow.compareTo("18:30");
        if (r >= 0) {
            return true;
        }
        return false;
    }

    /**
     * 获取最近三十天的日期 yyyy-mm-dd
     *
     * @return
     */
    public static List<String> getLastThirtyDayYmd() {
        ArrayList<String> dateList = new ArrayList<>(30);
        String currenTm = dateToYMD(new Date());
        dateList.add(currenTm);
        for (long i = 1; i < 30; i++) {
            Date d = new Date(System.currentTimeMillis() - (i * 86400000L));
            dateList.add(dateToYMD(d));
        }

        return dateList;
    }

    public static  String getYYYYMMDDYesterday() {
        LocalDateTime localDateTime = LocalDateTime.now();
        localDateTime = localDateTime.plusDays(-1);
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
        return df.format(localDateTime);
    }

}
